# asterisk-sip.pm
# Copyright (C) 2006  Stephane Alnet
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# 

# This file is part of the CarrierClass.net project.
# For more information: http://carrierclass.net/
#
package CCNv2::Provision::Asterisk::sip;
use strict;
use warnings;
use base qw(CCNCore::Provision::Base);
use CCN::Text;
use CCNCore::Scripting;

sub run()
{
    my $self = shift;
    return unless defined $self->p->{cp_member};

    my $SIPBINDPORT = 5062;
    my $REALM = $self->p->make_cluster_name($self->p->{cp_member},'cpc');

    my $video_support = 'no';

    CAT '/etc/asterisk/sip.conf', copyright(';'). <<"EOT";
[general]
static=yes
writeprotect=yes
;
bindaddr=0.0.0.0
realm=${REALM}
;
bindport=${SIPBINDPORT}
tos=lowdelay
amaflags=documentation
accountcode=sip
language=en
context=from-sip
rtptimeout=10800  ; 3 hours
rtpholdtimeout=300
nat=never
;
#include <config/codecs>
;
; Protocol specifics:
;
recordhistory=yes
srvlookup=yes
videosupport=${video_support}
useragent=CarrierClass.net
progressinband=never
promiscredir=yes     ; ?
; localnet=
; *** Inbound (shared) SIP trunks ***
#include <config/sip.siptrunks.register.conf>
#include <config/clients/_private/sip.register.conf>
;
; *** Outbound (shared) SIP trunk ***
#include <config/sip.proxy.conf>
#include <config/sip.siptrunks.conf>
;
EOT

    IF_CHANGED '/etc/asterisk/sip.conf' => CCNv2::Scripting::AST('sip reload');
}
1;